{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[143.73 145.83 143.68 144.02 143.5  142.62] <class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "price_list = [143.73, 145.83, 143.68, 144.02, 143.5, 142.62]\n",
    "price_array = np.array(price_list)\n",
    "print(price_array, type(price_array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 3]\n",
      " [2 4]] <class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "Ar = np.array([[1,3],[2,4]])\n",
    "print(Ar, type(Ar))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 2)\n"
     ]
    }
   ],
   "source": [
    "print(Ar.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 3]\n",
      "[2 4]\n"
     ]
    }
   ],
   "source": [
    "print(Ar[0])\n",
    "print(Ar[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the first column:  [1 2]\n",
      "the second column:  [3 4]\n"
     ]
    }
   ],
   "source": [
    "print('the first column: ', Ar[:,0])\n",
    "print('the second column: ', Ar[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 4.96793654  4.98244156  4.9675886   4.96995218  4.96633504  4.96018375]\n"
     ]
    }
   ],
   "source": [
    "print(np.log(price_array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "143.89666666666668\n",
      "0.9673790478515796\n",
      "863.38\n",
      "145.83\n"
     ]
    }
   ],
   "source": [
    "print(np.mean(price_array))\n",
    "print(np.std(price_array))\n",
    "print(np.sum(price_array))\n",
    "print(np.max(price_array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    143.73\n",
       "1    145.83\n",
       "2    143.68\n",
       "3    144.02\n",
       "4    143.50\n",
       "5    142.62\n",
       "dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price = [143.73, 145.83, 143.68, 144.02, 143.5, 142.62]\n",
    "s = pd.Series(price)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    143.73\n",
       "b    145.83\n",
       "c    143.68\n",
       "d    144.02\n",
       "e    143.50\n",
       "f    142.62\n",
       "dtype: float64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(price,index = ['a','b','c','d','e','f'])\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6    143.73\n",
       "5    145.83\n",
       "4    143.68\n",
       "3    144.02\n",
       "2    143.50\n",
       "1    142.62\n",
       "dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.index = [6,5,4,3,2,1]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5    145.83\n",
      "4    143.68\n",
      "3    144.02\n",
      "2    143.50\n",
      "1    142.62\n",
      "dtype: float64\n",
      "6    143.73\n",
      "5    145.83\n",
      "4    143.68\n",
      "3    144.02\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "print(s[1:])\n",
    "print(s[:-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "143.68\n",
      "6    143.73\n",
      "5    145.83\n",
      "4      0.00\n",
      "3    144.02\n",
      "2    143.50\n",
      "1    142.62\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "print(s[4])\n",
    "s[4] = 0\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    143.73\n",
      "1    145.83\n",
      "2    143.68\n",
      "3    144.02\n",
      "4    143.50\n",
      "5    142.62\n",
      "Name: Apple Price List, dtype: float64\n",
      "Apple Price List\n"
     ]
    }
   ],
   "source": [
    "s = pd.Series(price, name = 'Apple Price List')\n",
    "print(s)\n",
    "print(s.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04',\n",
      "               '2017-01-05', '2017-01-06'],\n",
      "              dtype='datetime64[ns]', freq='D')\n",
      "2017-01-01    143.73\n",
      "2017-01-02    145.83\n",
      "2017-01-03    143.68\n",
      "2017-01-04    144.02\n",
      "2017-01-05    143.50\n",
      "2017-01-06    142.62\n",
      "Freq: D, Name: Apple Price List, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "time_index = pd.date_range('2017-01-01',periods = len(s),freq = 'D')\n",
    "print(time_index)\n",
    "s.index = time_index\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6    143.73\n",
      "5    145.83\n",
      "4    143.68\n",
      "3    144.02\n",
      "2    143.50\n",
      "1    142.62\n",
      "Name: Apple Price List, dtype: float64\n",
      "142.62\n"
     ]
    }
   ],
   "source": [
    "s.index = [6,5,4,3,2,1]\n",
    "print(s)\n",
    "print(s[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "145.83\n"
     ]
    }
   ],
   "source": [
    "print(s.iloc[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "143.68\n"
     ]
    }
   ],
   "source": [
    "s.index = time_index\n",
    "print(s['2017-01-03'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2017-01-02    145.83\n",
      "2017-01-03    143.68\n",
      "2017-01-04    144.02\n",
      "2017-01-05    143.50\n",
      "Freq: D, Name: Apple Price List, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "print(s['2017-01-02':'2017-01-05'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6    143.73\n",
      "4    143.68\n",
      "2    143.50\n",
      "1    142.62\n",
      "Name: Apple Price List, dtype: float64\n",
      "[6    False\n",
      "5    False\n",
      "4    False\n",
      "3     True\n",
      "2    False\n",
      "1    False\n",
      "Name: Apple Price List, dtype: bool]\n"
     ]
    }
   ],
   "source": [
    "print(s[s < np.mean(s)] )\n",
    "print([(s > np.mean(s)) & (s < np.mean(s) + 1.64*np.std(s))])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
